//
//  String+Source.swift
//  GZWeibo007
//
//  Created by newuser on 16/1/4.
//  Copyright © 2016年 Apple. All rights reserved.
//

import Foundation

extension String {
/// 从新浪的来源字符串中返回来源
func source() -> String? {

     //创建正则表达式对象
    let regular = try! NSRegularExpression(pattern: ">(.*?)<", options: NSRegularExpressionOptions.DotMatchesLineSeparators)
    
    //让正则表达式对象去匹配
    let result = regular.firstMatchInString(self, options: NSMatchingOptions(rawValue: 0), range: NSRange(location: 0, length: self.characters.count))
    
    //判断匹配结果
    if result?.numberOfRanges > 1 {
     let range = result!.rangeAtIndex(1)
        //截取字符串
        let re = (self as NSString).substringWithRange(range)
         return "来自" + re
    } else {
    //匹配不到
        return nil
    }
}

}